#include "SQLTruncateStatement.h"

#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"
#include "../../../utils/log.h"

SQLTruncateStatement::SQLTruncateStatement()
{
  tableSources = std::make_shared<std::list<SQLExprTableSource_ptr>>();
  partitions = std::make_shared<std::list<SQLAssignItem_ptr>>();
  partitionsForADB = std::make_shared<std::list<SQLIntegerExpr_ptr>>();
}

SQLTruncateStatement::SQLTruncateStatement(DbType_ptr  dbType)
    : SQLStatementImpl(dbType)
{
  tableSources = std::make_shared<std::list<SQLExprTableSource_ptr>>();
  partitions = std::make_shared<std::list<SQLAssignItem_ptr>>();
  partitionsForADB = std::make_shared<std::list<SQLIntegerExpr_ptr>>();
}

SQLExprTableSource_list_ptr SQLTruncateStatement::getTableSources()
{
  return tableSources;
}

void SQLTruncateStatement::setTableSources(SQLExprTableSource_list_ptr tableSources)
{
  this->tableSources = tableSources;
}

void SQLTruncateStatement::addTableSource(SQLName_ptr name)
{
  SQLExprTableSource_ptr tableSource = SQLExprTableSource_ptr(new SQLExprTableSource(name));
  tableSource->setParent(SharedObject(SQLTruncateStatement));
  this->tableSources->push_back(tableSource);
}

void SQLTruncateStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLTruncateStatement)))
  {
    SQLObject_list_ptr  tmp = ListTran::tran_class<SQLExprTableSource, SQLObject>(tableSources);
    acceptChild(visitor, tmp);
  }
  visitor->endVisit(SharedObject(SQLTruncateStatement));
}

BOOL_ptr SQLTruncateStatement::isPurgeSnapshotLog()
{
  return purgeSnapshotLog;
}

void SQLTruncateStatement::setPurgeSnapshotLog(BOOL_ptr purgeSnapshotLog)
{
  this->purgeSnapshotLog = purgeSnapshotLog;
}

BOOL_ptr SQLTruncateStatement::isOnly()
{
  return only;
}

void SQLTruncateStatement::setOnly(BOOL_ptr only)
{
  this->only = only;
}

BOOL_ptr SQLTruncateStatement::getRestartIdentity()
{
  return restartIdentity;
}

void SQLTruncateStatement::setRestartIdentity(BOOL_ptr restartIdentity)
{
  this->restartIdentity = restartIdentity;
}

BOOL_ptr SQLTruncateStatement::getCascade()
{
  return cascade;
}

void SQLTruncateStatement::setCascade(BOOL_ptr cascade)
{
  this->cascade = cascade;
}

BOOL_ptr SQLTruncateStatement::isDropStorage()
{
  return dropStorage;
}

void SQLTruncateStatement::setDropStorage(BOOL_ptr dropStorage)
{
  this->dropStorage = dropStorage;
}

BOOL_ptr SQLTruncateStatement::isReuseStorage()
{
  return reuseStorage;
}

void SQLTruncateStatement::setReuseStorage(BOOL_ptr reuseStorage)
{
  this->reuseStorage = reuseStorage;
}

BOOL_ptr SQLTruncateStatement::isImmediate()
{
  return immediate;
}

void SQLTruncateStatement::setImmediate(BOOL_ptr immediate)
{
  this->immediate = immediate;
}

BOOL_ptr SQLTruncateStatement::isIgnoreDeleteTriggers()
{
  return ignoreDeleteTriggers;
}

void SQLTruncateStatement::setIgnoreDeleteTriggers(BOOL_ptr ignoreDeleteTriggers)
{
  this->ignoreDeleteTriggers = ignoreDeleteTriggers;
}

BOOL_ptr SQLTruncateStatement::isRestrictWhenDeleteTriggers()
{
  return restrictWhenDeleteTriggers;
}

void SQLTruncateStatement::setRestrictWhenDeleteTriggers(BOOL_ptr restrictWhenDeleteTriggers)
{
  this->restrictWhenDeleteTriggers = restrictWhenDeleteTriggers;
}

BOOL_ptr SQLTruncateStatement::isContinueIdentity()
{
  return continueIdentity;
}

void SQLTruncateStatement::setContinueIdentity(BOOL_ptr continueIdentity)
{
  this->continueIdentity = continueIdentity;
}

SQLExprTableSource_list_ptr SQLTruncateStatement::getChildren()
{
  return tableSources;
}

BOOL_ptr SQLTruncateStatement::isIfExists()
{
  return ifExists;
}

void SQLTruncateStatement::setIfExists(BOOL_ptr ifExists)
{
  this->ifExists = ifExists;
}

SQLAssignItem_list_ptr SQLTruncateStatement::getPartitions()
{
  return partitions;
}

BOOL_ptr SQLTruncateStatement::isPartitionAll()
{
  return partitionAll;
}

void SQLTruncateStatement::setPartitionAll(BOOL_ptr partitionAll)
{
  this->partitionAll = partitionAll;
}

std::shared_ptr<std::list<SQLIntegerExpr_ptr>> SQLTruncateStatement::getPartitionsForADB()
{
  return partitionsForADB;
}
